<template>
  <!-- 首页菜单项只在顶层显示 -->
  <el-menu-item v-if="isTopLevel" :index="'1'" :route="'/home'">
    <el-icon><HomeFilled /></el-icon>
    <span>{{ $t("nav.home") }}</span>
  </el-menu-item>
  
  <template v-for="menu in menuList" :key="menu.index">
    <!-- 有子菜单的情况 -->
    <el-sub-menu
      v-if="menu.children && menu.children.length"
      :index="menu.index"
    >
      <template #title>
        <el-icon><component :is="menu.icon" /></el-icon>
        <span>{{ menu.title }}</span>
      </template>
      <!-- 递归调用自身处理子菜单，传递isTopLevel为false -->
      <recursive-menu :menu-list="menu.children" :is-top-level="false" />
    </el-sub-menu>
    <!-- 没有子菜单的情况 -->
    <el-menu-item v-else :index="menu.index" :route="menu.route">
      <el-icon><component :is="menu.icon" /></el-icon>
      <span>{{ menu.title }}</span>
    </el-menu-item>
  </template>
</template>

<script setup>
defineProps({
  menuList: {
    type: Array,
    required: true,
    default: () => [],
  },
  isTopLevel: {
    type: Boolean,
    default: true,
  },
});
</script>
